package weaver.interfaces.ht.wlbmsq;

import com.sap.mw.jco.IFunctionTemplate;
import com.sap.mw.jco.JCO;
import com.weaver.integration.datesource.SAPInterationOutUtil;
import com.weaver.integration.log.LogInfo;
import weaver.general.Util;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2020-04-11
 * @Description: ${description}
 * @ModifyLog:
 **/

public class ZIF_MATERIAL_CREATE {
    public Map execute(Map<String, String> map,String curdate) {
        SAPInterationOutUtil outUtil = new SAPInterationOutUtil();
        JCO.Client myConnection = (JCO.Client)outUtil.getConnection("1", new LogInfo());
        myConnection.connect();
        JCO.Repository myRepository = new JCO.Repository("Repository",myConnection); // 只一个名字
        IFunctionTemplate ft = myRepository.getFunctionTemplate("ZIF_MATERIAL_CREATE");//设置BAPI函数
        JCO.Function bapi = ft.getFunction();
        JCO.ParameterList input = bapi.getImportParameterList();//输入参数和结构处理
      
        input.setValue("FI01", "I_CNAME");
        input.setValue(curdate, "I_VCDAT");
        //入参为结构
        JCO.Structure stu1 = input.getStructure("IT_ZTMDM003");
        stu1.setValue(map.get("ZTXT04"), "ZTXT04");
        stu1.setValue(map.get("MTART"), "MTART");
        stu1.setValue(map.get("WERKS"), "WERKS");
        stu1.setValue(map.get("MAKTX"), "MAKTX");
        stu1.setValue(map.get("MEINS"), "MEINS");
        stu1.setValue("90", "SPART");
        stu1.setValue(map.get("MATKL"), "MATKL");
        stu1.setValue(map.get("EKGRP"), "EKGRP");
        stu1.setValue("X", "XCHPF");
        stu1.setValue(map.get("MFRPN"), "MFRPN");
        stu1.setValue("1111111111", "STAWN");
        stu1.setValue("R02", "DISGR");
        stu1.setValue("ND", "DISMM");
        stu1.setValue(map.get("DISPO"), "DISPO");
        stu1.setValue("EX", "DISLS");
        stu1.setValue("000", "FHORI");
        stu1.setValue(map.get("EISBE"), "EISBE");
        stu1.setValue("M", "PERKZ");
        stu1.setValue("02", "MTVFP");
        stu1.setValue("G", "PRMOD");
        stu1.setValue("HZA00", "PRCTR");
        stu1.setValue("Z", "BWTTY");
        stu1.setValue(map.get("BKLAS"), "BKLAS");
        stu1.setValue(map.get("MODEL"), "MODEL");
        //执行函数
        myConnection.execute(bapi);
        JCO.ParameterList out = bapi.getExportParameterList();//输出参数和结构处理
        JCO.ParameterList Table00 = bapi.getTableParameterList();//输出表的处理
        //返回处理结果以及日志
        Map<String, String> mapreturn = new HashMap<>();
        String E_MATNR = Util.null2String(out.getValue("E_MATNR")) ;//编码
        String E_MSG = Util.null2String(out.getValue("E_MSG"));//文本
        String E_CHK_TYPE = Util.null2String(out.getValue("E_CHK_TYPE"));//标识
        mapreturn.put("E_MATNR", E_MATNR);
        mapreturn.put("E_MSG", E_MSG);
        mapreturn.put("E_CHK_TYPE", E_CHK_TYPE);
        System.out.println(mapreturn.toString());
        JCO.releaseClient(myConnection);
        return mapreturn;
    }

    public static void main(String[] args) {
        Map map = new HashMap();
        map.put("ZTXT04", "SPMD");
        map.put("MTART", "ERSA");
        map.put("WERKS", "1000");
        map.put("MAKTX", "ROLLER GUIDE(O)");
        map.put("MEINS", "EA");
        map.put("MATKL", "S143");
        map.put("EKGRP", "205");
        map.put("MFRPN", "418X25X10");
        map.put("DISPO", "001");
        map.put("EISBE", "0.000");
        map.put("BKLAS", "3040");
        map.put("MODEL", "NEODRY15EU-031C");
        ZIF_MATERIAL_CREATE create = new ZIF_MATERIAL_CREATE();
        create.execute(map,"20200703");
    }

}
